package sziit.znk.services.impl;

import sziit.znk.services.BeanService;
import sziit.znk.utils.factory.BeanFactory;
import sziit.znk.utils.exception.BeanFactoryException;

import java.util.Map;

public class OptBeanContainer implements BeanService {

    private Map<String, Object> beanContainer = BeanFactory.getBeanContainer();

    @Override
    public Object getBean(String id) {
        Object o = beanContainer.get(id);
        try {
            if (o == null) throw new BeanFactoryException();
        } catch (BeanFactoryException e) {
            e.showGetBeanException();
        }
        return o;
    }

    @Override
    public Map<String, Object> getBeanContainer() {
        try {
            if (beanContainer == null) throw new BeanFactoryException();
        } catch (BeanFactoryException e) {
            e.showGetContainerException();
        }
        return beanContainer;
    }

    @Override
    public void addBean(String id, Object o) {
        beanContainer.put(id, o);
    }

    @Override
    public void deleteBean(String id) {
        beanContainer.remove(id);
    }
}
